/*    This file is part of libepistle.
 *
 *    libepistle is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    libepistle is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with libepistle.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef EPISTLE_MSG_SERVER_H
#define EPISTLE_MSG_SERVER_H

#include "msgr.h"

typedef struct {
	int epoll_fd;
	uint32_t max_len;
	Map msgrs;
} Msg_server;

typedef int (*Add_msgr)(Msg_server *server, int fd, int server_fd,
			Err *err, void *extra);

typedef int (*Remove_msgr)(Msg_server *server, int fd, Err *err, void *extra);

typedef int (*React_msg)(Msg_server *server, Msgr *msgr,
			 Err *err, void *extra);

int
msg_server_init(Msg_server *server, int epoll_fd, uint32_t max_len,
		Disposer *extra_dspr, Err *err);

void
msg_server_dispose(Msg_server *server);

int
msg_server_on(Msg_server *server, int socket, Err *err);

int
msg_server_off(Msg_server *server, int socket, Err *err);

Msgr *
msg_server_add(Msg_server *server, int fd, void *extra, Err *err);

int
msg_server_remove(Msg_server *server, int fd, void **extra, Err *err);

Msgr *
msg_server_get(Msg_server *server, int fd);

int
msg_server(Msg_server *server, Add_msgr add, Remove_msgr remove,
	   React_msg react, Err *err, void *extra);

#endif
